﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace WebApp
{
    public partial class UpPwd : System.Web.UI.Page
    {
        //protected void Page_Load(object sender, EventArgs e)
        //{

        //}


        protected void btnMPY_Click(object sender, EventArgs e)
        {
            try
            {
                string strCn = "server=pc.hstc.cn;database=dhd2014112138;uid=2014112138;pwd=19960516";
                SqlConnection conn = new SqlConnection(strCn);
                conn.Open();
                string strSql = "select * from UserManager where Manager='" + this.txtMNa.Text + "' and  Password='" + txtMPwd.Text + "'";
                SqlCommand cmd = new SqlCommand(strSql, conn);
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                if (dr.Read())
                {
                    string strCnn = "server=pc.hstc.cn;database=dhd2014112138;uid=2014112138;pwd=19960516";
                    SqlConnection con = new SqlConnection(strCnn);
                    con.Open();
                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    SqlStringBuilder.Append("UPDATE  UserManager ");
                    SqlStringBuilder.AppendFormat("SET     Password = N'{0}'", this.txtMPwd1.Text);
                    SqlStringBuilder.AppendFormat("WHERE   (Manager = N'{0}') ", this.txtMNa.Text);

                    int iUpd = SqlHelper.ExecuteNonQuery(SqlStringBuilder.ToString());
                    if (iUpd > 0)
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('修改成功！现在可以用新密码登录！')", true);
                    }

                }

            }
            catch (Exception ex)
            {
                this.lblM.Text = "修改失败！具体原因：" + ex.Message;
            }
        }

        protected void btnMPNew_Click(object sender, EventArgs e)
        {
            this.txtMNa.Text = "";
            this.txtMPwd.Text = "";
            this.txtMPwd1.Text = "";
            this.txtMPwd2.Text = "";
        }
        
    }
}